package com.sxt.sys.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.sxt.sys.vo.NoticeVo;
import com.sxt.sys.SYSConstast.SYSConstast;
import com.sxt.sys.domain.Notice;
import com.sxt.sys.service.NoticeService;
import com.sxt.sys.utils.DataGridView;
import com.sxt.sys.utils.ResultObj;

@RestController
@RequestMapping("notice")
public class NoticeCotroller {
	
	
	@Autowired
	private NoticeService noticeService;
	
	
	
	@RequestMapping("loadAllnotice")
	public DataGridView loadAllnotice(NoticeVo noticeVo) {
		
		return noticeService.queryAllNotice(noticeVo);
	}
	
	@RequestMapping("deleteNotice")
	public ResultObj deleteNotice(NoticeVo noticeVo) {
		Integer code=1;
		String msg="";
		try {
			Integer info = noticeService.deleteNotice(noticeVo.getId());
			code = info;
			msg = info > 0 ?SYSConstast.DELETE_LOGININFOR_TRUE:SYSConstast.DELETE_LOGININFOR_FALSE;
		} catch (Exception e) {
			code = 0;
			msg = SYSConstast.DELETE_LOGININFOR_FALSE;
		}
		return new ResultObj(code , msg);
	}
	
	@RequestMapping("updateNotice")
	public ResultObj updateNotice(NoticeVo noticeVo) {
		Integer code=1;
		String msg="";
		try {
			Integer info = noticeService.updateNotice(noticeVo);
			code = info;
			msg = info > 0 ?SYSConstast.UPDATE_LOGININFOR_TRUE:SYSConstast.UPDATE_LOGININFOR_FALSE;
		} catch (Exception e) {
			code = 0;
			msg = SYSConstast.UPDATE_LOGININFOR_FALSE;
		}
		return new ResultObj(code , msg);
	}
	
	
	@RequestMapping("addNotice")
	public ResultObj addNotice(NoticeVo noticeVo) {
		Integer code=1;
		String msg="";
		try {
			Integer info = noticeService.addNotice(noticeVo);
			code = info;
			msg = info > 0 ?SYSConstast.ADD_LOGININFOR_TRUE:SYSConstast.ADD_LOGININFOR_FALSE;
		} catch (Exception e) {
			code = 0;
			msg = SYSConstast.ADD_LOGININFOR_FALSE;
		}
		return new ResultObj(code , msg);
	}
	
	@RequestMapping("loadNoticeById")
	public Notice loadNoticeById(Integer id) {
		
		return noticeService.loadNoticeById(id);
	}
}
